﻿@page
@model IndexModel
@{
    Layout = null;
}
<html>
<head>
    <meta charset="UTF-8" />
</head>
<body>
    编译ToolGood.Algorithm.WebAssembly项目，生成文件夹下的wwwroot文件夹中的_framework文件夹中就是生成的WebAssembly和相关文件
    <br />
    我们运行前端项目. 由于Blazor会生成dat、dll等不被Web服务器默认接受的文件类型，所以请确保在Web服务器上为如下格式的文件配置MimeType：.gz、.dat、.wasm

    <br />
    不支持Md5、HmacMd5 两个公式

    <pre>
    DistanceUnitType = new class { constructor() { this.MM = 1; this.CM = 2; this.DM = 3; this.M = 4; this.KM = 5; } }();
    AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }();
    VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }();
    MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }();
    AlgorithmEngine = class {
        constructor() {
            this.UseExcelIndex = true;
            this.UseTempDict = false;
            this.UseLocalTime = false;
            this.DistanceUnit = DistanceUnitType.M;
            this.AreaUnit = AreaUnitType.M2;
            this.VolumeUnit = VolumeUnitType.M3;
            this.MassUnit = MassUnitType.KG;
            this.IgnoreCase = false;
        }
        TryEvaluateString = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateString', exp, def, data, JSON.stringify(this)); }
        TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); }
        TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); }
        TryEvaluateDateTime = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, JSON.stringify(this)); }
        TryEvaluate = function (exp, def, data) {
            if (def == null) { return this.TryEvaluateString(exp, def, data); }
            if (typeof def == "number") { return this.TryEvaluateNumber(exp, def, data); }
            if (typeof def == "boolean") { return this.TryEvaluateBool(exp, def, data); }
            if (typeof def == "object" && def instanceof Date) { return this.TryEvaluateDateTime(exp, def, data); }
            return this.TryEvaluateString(exp, def, data);
        }
    };

    window.onload = async function () {
        await Blazor.start();
        var ae = new AlgorithmEngine();
        r = ae.TryEvaluate("'S' & 1", "")
        alert("'S' & 1 =>" + r);
        r = ae.TryEvaluate("1+2", 0)
        alert("1+2 =>" + r);
        r = ae.TryEvaluate("1=1", false)
        alert("1=1 =>" + r);
        r = ae.TryEvaluate("date(2014,1,2)", new Date())
        alert('date(2014,1,2) =>' + r);
    };
    </pre>
</body>
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script>
    DistanceUnitType = new class { constructor() { this.MM = 1; this.CM = 2; this.DM = 3; this.M = 4; this.KM = 5; } }();
    AreaUnitType = new class { constructor() { this.MM2 = 11; this.CM2 = 12; this.DM2 = 13; this.M2 = 14; this.KM2 = 15; } }();
    VolumeUnitType = new class { constructor() { this.MM3 = 21; this.CM3 = 22; this.DM3 = 23; this.M3 = 24; this.KM3 = 25; } }();
    MassUnitType = new class { constructor() { this.G = 31; this.KG = 32; this.T = 33; } }();
    AlgorithmEngine = class {
        constructor() {
            this.UseExcelIndex = true;
            this.UseTempDict = false;
            this.UseLocalTime = false;
            this.DistanceUnit = DistanceUnitType.M;
            this.AreaUnit = AreaUnitType.M2;
            this.VolumeUnit = VolumeUnitType.M3;
            this.MassUnit = MassUnitType.KG;
            this.IgnoreCase = false;
        }
        TryEvaluateString = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateString', exp, def, data, JSON.stringify(this)); }
        TryEvaluateNumber = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateNumber', exp, def, data, JSON.stringify(this)); }
        TryEvaluateBool = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateBool', exp, def, data, JSON.stringify(this)); }
        TryEvaluateDateTime = function (exp, def, data) { return DotNet.invokeMethod('ToolGood.Algorithm.WebAssembly', 'TryEvaluateDateTime', exp, def, data, JSON.stringify(this)); }
        TryEvaluate = function (exp, def, data) {
            if (def == null) { return this.TryEvaluateString(exp, def, data); }
            if (typeof def == "number") { return this.TryEvaluateNumber(exp, def, data); }
            if (typeof def == "boolean") { return this.TryEvaluateBool(exp, def, data); }
            if (typeof def == "object" && def instanceof Date) { return this.TryEvaluateDateTime(exp, def, data); }
            return this.TryEvaluateString(exp, def, data);
        }
    };

    window.onload = async function () {
        await Blazor.start();
        var ae = new AlgorithmEngine();
        r = ae.TryEvaluate("'S' & 1", "")
        alert("'S' & 1 =>" + r);
        r = ae.TryEvaluate("1+2", 0)
        alert("1+2 =>" + r);
        r = ae.TryEvaluate("1=1", false)
        alert("1=1 =>" + r);
        r = ae.TryEvaluate("date(2014,1,2)", new Date())
        alert('date(2014,1,2) =>' + r);
        r = ae.TryEvaluate("SHA256('123')", "")
        alert("SHA256('123') =>" + r);
        r = ae.TryEvaluate("MD5('123')", "")
        alert("MD5('123') =>" + r);
    };
</script>
</html>
